Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary .units in Validator #2182

Merged
merged 4 commits into from
Apr 8, 2024

Conversation

kyri-petrou
Copy link
Collaborator

In many places in the Validator, we use .unit after ZPure.when to make the compiler happy. However, this adds an unnecessary flatMap each time we do this.

To avoid this, we add a failWhen method which unlike ZPure.when, it returns an EReader[Any, ValidationError, Unit], so we don't need to call .unit afterwards

@@ -1262,22 +1225,27 @@ object Validator {
*/
private def validateAll[R, A, B](
in: Iterable[A]
)(f: A => EReader[R, ValidationError, B]): EReader[R, ValidationError, Unit] =
)(f: A => EReader[R, ValidationError, Unit]): EReader[R, ValidationError, Unit] =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the B type param

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops 😅 Done

Copy link
Owner

@ghostdogpr ghostdogpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

@kyri-petrou kyri-petrou merged commit 29a868b into series/2.x Apr 8, 2024
10 checks passed
@kyri-petrou kyri-petrou deleted the validator-microoptimizations branch April 8, 2024 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants